<?php
defined('_JEXEC') or die('Restricted access');
$user = JFactory::getUser();
$guest = $user->get('guest');
//print_r($user);exit();
$template = "templates/tpl_automobil/";
?>
<script type="text/javascript" src="<?php echo $template;?>js/jquery.json-2.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
	$('.btn-auto').live('click',function(){
		$('#at').val(1);
		if($('#name').val() == ""){
			$('#alert').html('Udfyld venligst dit navn');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('name');
			return false;
		}
		if($('#email').val() == ""){
			$('#alert').html('Udfyld venligst email');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('email');
			return false;	
		}
		else{
			if(!isEmail($('#email').val())){
				$('#alert').html('Indtast en gyldig email');
				$('#backoverlay').show();
				$('#show_popup').show();
				$('#s_focus').html('email');
				return false; 
			}
		}
		if($('#address').val() == ""){
			$('#alert').html('Udfyld venligst adresse');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('address');
			return false;	
		}
		if($('#code').val() == ""){
			$('#alert').html('Udfyld venligst postnr.');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('code');
			return false;
		}
		if($('#city').val() == ""){
			$('#alert').html('Udfyld venligst by');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('city');
			return false;
		}
		if(!$('#aa').is(":checked")){
			$('#alert').html('Venligst accepterer vores salgs- og leveringsbetingelser');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('aa');
			return false;
		}
		
		$('#alert_at').html('<p>Er du sikkert på at vælge denne placering:<br /> Dansk Automobil Børs</p>');
		$('#backoverlay_at').show();
		$('#show_popup_at').show();
		$('#ok_link').live('click',function(){$('#registerUserForm').submit();});
		return false;
	});
	
	$('.btn-other').live('click',function(){
		$('#at').val(0);
		if($('#name').val() == ""){
			$('#alert').html('Udfyld venligst dit navn');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('name');
			return false;
		}
		if($('#email').val() == ""){
			$('#alert').html('Udfyld venligst email');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('email');
			return false;	
		}
		else{
			if(!isEmail($('#email').val())){
				$('#alert').html('Indtast en gyldig email');
				$('#backoverlay').show();
				$('#show_popup').show();
				$('#s_focus').html('email');
				return false; 
			}
		}
		if($('#address').val() == ""){
			$('#alert').html('Udfyld venligst adresse');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('address');
			return false;	
		}
		if($('#code').val() == ""){
			$('#alert').html('Udfyld venligst postnr.');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('code');
			return false;
		}
		if($('#city').val() == ""){
			$('#alert').html('Udfyld venligst by');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('city');
			return false;
		}
		if(!$('#aa').is(":checked")){
			$('#alert').html('Venligst accepterer vores salgs- og leveringsbetingelser');
			$('#backoverlay').show();
			$('#show_popup').show();
			$('#f_focus').html('aa');
			return false;
		}
		
		$('#alert_at').html('<p>Er du sikkert på at vælge denne placering:<br /> På min adresse</p>');
		$('#backoverlay_at').show();
		$('#show_popup_at').show();
		$('#ok_link').live('click',function(){$('#registerUserForm').submit();});
		return false;
	});
    
    isEmail=function(string) {
		if (string.search(/^\w+((-\w+)|(\.\w+)|(\_\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/) != -1)
			return true;
		else return false;
    };
	loadData = function(emailAdd){
		jQuery.ajax({
			type: 'POST',
			url: ('<?php echo $this->baseurl ?>/index.php?option=com_ecommerce&task=loadUserData'),
			data: {email: emailAdd},
			success: function(result){
				result=jQuery.evalJSON(result);
				if(result.status == 1){
					$('#name').val(result.name);
					$('#company').val(result.company);
					$('#cvr').val(result.cvr);
					$('#address').val(result.address);
					$('#code').val(result.code);
					$('#city').val(result.city);
					$('#phone').val(result.phone);
					$('#userid').val(result.userid);
				}
			},
			dataType: 'JSON'
		});
	}
});
jQuery(document).ready(function(cash) {
	if(jQuery("#system-message  ul li").html()!=null)
	{
		$('#alert').html(jQuery("#system-message  ul li").html());
		$('#backoverlay').show();
		$('#show_popup').show();
	} 
});
</script>
<p><span class="float_left f28">Tilmelding af bil</span><span class="link-login"><a href="index.php?option=com_user&view=user&layout=profile&Itemid=13">
  <?php if($user->guest==0) {echo  "Min Profil";} ;?>
  </a><a href="index.php?option=com_user&view=login&task=logout&Itemid=13" class="m12l">
  <?php if($user->guest==0) {echo  "Log ud";};?>
  </a></span></p>
<div class="cb"></div>
<div class="tt m10b"></div>
<div class="p5t">
  <div class="box_gude p10l p15t p30b"> <?php echo $this->article;?>
    <div class="w720 form_tilmelding1 float_left">
      <div class="form_tilmelding w462 float_left">
		<h3 class="m15t boder_b_d m10b">Kontaktinformation</h3>
      	<form action="index.php" method="post" id="registerUserForm" name="registerUserForm" enctype="multipart/form-data">
        <label>Dit fulde navn:<span>*</span></label>
        <input type="text" value="<?php if(!$guest) echo $user->name;?>" class="txt_tilmelding w390" name="name" id="name" />
        <label>E-mail:<span>*</span></label>
        <input type="text" value="<?php if(!$guest) echo $user->email;?>" class="txt_tilmelding w390" name="email" id="email" onblur="loadData(this.value);" />
        <label>Firmanavn:</label>
        <input type="text" value="<?php if(!$guest) echo $user->get('company');?>" class="txt_tilmelding w390" name="company" id="company" />
        <label>CVR-nr:</label>
        <input type="text" value="<?php if(!$guest) echo $user->get('cvr');?>" class="txt_tilmelding w390" name="cvr"  id="cvr"/>
        <label>Adresse:<span>*</span></label>
        <input type="text" value="<?php if(!$guest) echo $user->get('address');?>" class="txt_tilmelding w390" name="address" id="address" />
        <label>Postnr.<span>*</span></label>
        <input type="text" value="<?php if(!$guest) echo $user->get('code');?>" class="txt_tilmelding width80" name="code" id="code" maxlength="4" />
        <label style="text-align:center; line-height:29px;" id="w40">By:<span>*</span></label>
        <input type="text" value="<?php if(!$guest) echo $user->get('city');?>" id="city" class="txt_tilmelding w171" name="city" />
        <label>Telefon:</label>
        <input type="text" value="<?php if(!$guest) echo $user->get('phone');?>" class="txt_tilmelding w390" name="phone" id="phone" />
        <div class="cb"></div>
        <input name="check" id="aa" type="checkbox" value="" />
    &nbsp;<a href="#TB_inline?height=350&width=700&inlineId=hiddenContent&modal=false" title="Handelsbetingelser" class="thickbox">Jeg har læst og accepteret auktionsbetingelser</a>
        <h3 class="m30t boder_b_d m10b">Placering</h3>
		
        <div class="m15t w593">
            <a href="javascript:void(0);" class="btn-auto float_left btn"></a>
            <a href="javascript:void(0);" class="btn-other float_left btn m5l"></a>
        </div>
            
        <input type="submit" name="sendInformation" id="sendInformation" style="display:none" />
        <input type="hidden" name="option" value="com_ecommerce" />
        <input type="hidden" name="task" value="registerUser" />
        <input type="hidden" name="userid" value="<?php echo $user->id;?>" id="userid" />
        <input type="hidden" name="at" id="at" value="1" />
      	</form>
      </div>
    </div>
    <p class="cb"></p>
  </div>
</div>
<div class="bg_alert" id="show_popup_at" style="display:none; position: fixed; top: 35%; left: 50%; z-index:10001; margin-left:-140px;">
    <span id="f_focus" style="display:none;"></span>
    <div style="margin:0; padding-top:12px; padding-right: 15px; min-height:60px; font-size: 12px;" id="alert_at"></div>
    <div class="row-btn">
    	<a href="javascript:void(0);" id="ok_link" class="btn" onclick="close_popup_at();"><img alt="" src="templates/tpl_automobil/images/btn_ok.png"></a>
        <a href="javascript:void(0);" onclick="close_popup_at();"><img src="templates/tpl_automobil/images/bt_luk1.png" alt="" /></a>
    </div>
</div>
<div style="display: none;position: fixed; top: 0;left: 0;width: 100%;height: 100%;background-color: #000000;z-index:10000;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);" id="backoverlay_at"></div>
<div id="hiddenContent" style="display:none;">
<?php 
$db	= &JFactory::getDBO();
$query = "SELECT introtext FROM #__content WHERE id = 6";
$db->setQuery($query);
$temp1=$db->loadObject();
 echo $temp1->introtext;
?>
</div>